package com.wulwu.rocketmq.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author wuxb
 * @Date 2022/3/9 18:39
 */
@Api(tags = "发送消息")
@RestController
@RequestMapping(value = "/send/")
public class RocketSendController {

    @Autowired
    private DefaultMQProducer defaultMQProducer;

    @ApiOperation(value = "固定消息")
    @RequestMapping("msg")
    public String sendMessage() {
        try {
            Message sendMsg = new Message("MutongTopic",
                    "MutongTag",
                    "open_account_key", "testRocketMQ".getBytes());
            SendResult send = defaultMQProducer.send(sendMsg);
            System.out.println("====>" + JSON.toJSONString(send));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ok";
    }

}
